package com.lz.football.module.compete.matchResult
{
	import com.common.utils.Reflection;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * 比赛结果列表（国家） 
	 * @author Administrator
	 * 
	 */	
	public class MatchResultListView extends Sprite implements IComponent
	{
		private var _list:Vector.<ResultItem>;
		public function MatchResultListView()
		{
			super();
//			initUI();
		}
		
		public function initUI(view:Object=null):void
		{
			_list = new Vector.<ResultItem>();
			
//			for(var i:int = 0;i < 3;i++)
//			{
//				var item:ResultItem = new ResultItem();
//				item.initUI();
//				item.y = 23 * i;
//				this.addChild(item);
//				_list.push(item);	
//			}
//			addItem();
			addEvtListener();
			this.cacheAsBitmap = true;
		}
		/**
		 *增加item 
		 * 
		 */
		public function addItem($obj:Object):void
		{
			var item:ResultItem = new ResultItem();
			item.initUI();
			item.setData($obj);
			item.y = 23 * 3;
			this.addChild(item);
			_list.push(item);
			item.alpha = 0;
			if(_list.length > 3)// item大于3个
			{
				TweenLite.to(_list[0],0.5,{y:-23,alpha:0,onComplete:onComplete});
				TweenLite.to(_list[1],0.5,{y:0});
				TweenLite.to(_list[2],0.5,{y:23});
				TweenLite.to(_list[3],0.5,{y:46,alpha:1});
			}else
			{
				TweenLite.to(_list[_list.length - 1],0.5*(5 - _list.length ),{y:23 * (_list.length - 1),alpha:1});
			}
				
			
		}
		/**
		 *第一个移动完成
		 * 移除第一个item 
		 * 
		 */		
		private function onComplete():void
		{
			_list.shift().destroyView();
		}
		
		public function addEvtListener():void
		{
//			AppEventDispatcher.getInstance().addEventListener("test",ontestHandler);
		}
		
		protected function ontestHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			addItem(null);
		}
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
			if(this.parent)this.parent.removeChild(this);
			var item:ResultItem
			while(_list.length)
			{
				item = _list.pop();
				TweenLite.killTweensOf(item);
				item.destroyView();
			}
			_list = null;
		}
	}
}